<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    /*重新设置样式*/
    .form-control {
        width: 196px !important;
        height: 34px !important;
        padding: 10px !important;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini" onload="checkBrowser()">
<!--选择外购件库存模态框-->
<div class="modal fade" id="modal-select-purchase">
    <div class="modal-dialog" style="width: 1350px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">外购件库在<span id="warehouseCode" style="color: red"></span>库明细信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">
                                <form id="queryFormByPurchase">
                                    <div class="row" id="HiddenDiv">
                                        <div class="form-inline">
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>项目编号</label>
                                                <input type="text" id="ityProCode" name="ityProCode"
                                                       class="form-control"
                                                       placeholder="请输入项目编号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>项目名称</label>
                                                <input type="text" id="ityProName" name="ityProName"
                                                       class="form-control"
                                                       placeholder="请输入项目名称">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    物料描述
                                                </label>
                                                <input type="text" id="ityMatDesc" name="ityMatDesc"
                                                       class="form-control"
                                                       placeholder="请输入物料描述">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    SAP物料编码
                                                </label>
                                                <input type="text" id="itySapCode" name="itySapCode"
                                                       class="form-control"
                                                       placeholder="请输入SAP物料编码">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>跟踪号</label>
                                                <input type="text" id="ityTrackCode" name="ityTrackCode"
                                                       class="form-control"
                                                       placeholder="请输入跟踪号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    生产状态
                                                </label>
                                                <select id="proProductionStatus" name="proProductionStatus"
                                                        class="form-control select"
                                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                                    <option value="" selected="selected">全部</option>
                                                    <option value="-1">无状态</option>
                                                    <option value="1">未开始</option>
                                                    <option value="2">执行中</option>
                                                    <option value="3">已完成</option>
                                                    <option value="4">取消</option>
                                                    <option value="5">暂缓</option>
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    库位
                                                </label>
                                                <input type="text" id="ityPosition" name="ityPosition"
                                                       class="form-control"
                                                       placeholder="请输入库位">
                                            </div>

                                            <div class="form-group"
                                                 style="margin-right: 10px;margin-bottom: 5px;display: none">
                                                <label>仓库</label>
                                                <select id="ityWhiId" class="form-control select" name="ityWhiId"
                                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;">
                                                </select>
                                                <!--<input type="text" id="stockMaterialTypeQuery" name="stockMaterialTypeQuery"
                                                       class="form-control"
                                                       placeholder="请输入原料类型">-->
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <button type="button" class="btn btn-success" id="btn_inventorySearch">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body"
                                 style="padding-top: 0px;padding-bottom: 0px;margin-top: -50px;height: 600px">
                                <table id="inventoryQueryTable" class="table table-bordered " width="100%"
                                       data-height="400">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" style="width: 82px;height: 34px;" class="btn btn-info"
                        id="btn-selectMaterial-commit"
                        shiro:hasPermission="purwar:puralloutwar:edit">确定
                </button>
                <button type="button" style="width: 82px;height: 34px;" class="btn btn-default" data-dismiss="modal">
                    取消
                </button>
            </div>
        </div>
    </div>

</div>
<section class="content-header">
    <h1>串料申请</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        单据编号
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoCode" type="text" class="form-control text" maxlength="50"
                                               placeholder="请输入单据编号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        需求项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoNeedProCode" type="text" class="form-control text"
                                               placeholder="请输入需求项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        需求项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoNeedProName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入需求项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        需求物料描述
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoNeedMatName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入需求物料描述"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        挪用项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoUseProCode" type="text" class="form-control text"
                                               placeholder="请输入挪用项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        挪用项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoUseProName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入挪用项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        挪用物料描述
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoUseMatName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入挪用物料描述"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        制单人
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoAppPerson" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入申请者信息"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        挪用跟踪号
                                    </label>
                                    <label class="control-label">
                                        <input name="ityTrackCode" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入挪用跟踪号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        挪用SAP编码
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoUseItySapCode" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入挪用SAP编码"/>
                                    </label>
                                </div>
                                <div id="ceoRemoveUserName" class="form-group"
                                     style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        申请删除者
                                    </label>
                                    <label class="control-label">
                                        <input name="ceoRemoveUserName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入申请删除者"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        删除状态
                                    </label>
                                    <label class="control-label">
                                        <select name="ceoDataStatus" class="form-control"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: 60px!important;">
                                            <!--<option value="-1">全部</option>-->
                                            <option value="">全部</option>
                                            <option value="0" selected="selected">未删除</option>
                                            <option value="1">已删除</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        串料状态
                                    </label>
                                    <label class="control-label">
                                        <select name="ceoAppyStatusTextSelect" class="selectpicker"
                                                multiple data-actions-box="true"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                            <!--<option value="-1">全部</option>-->
                                            <option value="4" selected="selected">被驳回</option>
                                            <option value="1" selected="selected">未提交</option>
                                            <option value="2">已提交</option>
                                            <option value="3">已执行</option>
                                            <option value="5">已出库</option>
                                        </select>
                                    </label>
                                    <input name="ceoAppyStatusText" type="hidden" style="display: none" value="1,4"/>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        仓库
                                    </label>
                                    <label class="control-label">
                                        <select name="whiId" class="selectpicker"
                                                multiple data-actions-box="true"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                            <option selected th:each="item:${warehouseInfoList}"
                                                    th:value="${item.whiId}"
                                                    th:text="${item.whiName}"></option>
                                        </select>
                                        <input th:value="${whiIds}" type="hidden" style="display: none" name="whiIds">
                                    </label>
                                    <input name="ceoAppyStatusText" type="hidden" style="display: none" value="1,4"/>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="width:85px;text-align: right">
                                        制单日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div id="removeDate" class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        删除日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginRemoveDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endRemoveDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div id="submitDate" class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        提交日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginSubmitDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endSubmitDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <button type="button" class="btn btn-success" id="btn-search">搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <button class="btn btn-success" id="btn_submitSelectItems" style="width: 82px;height: 34px;"> 批量提交
                    </button>
                    <a shiro:hasPermission="purinv:purchalist:edit" href="/purchase/change/createPage"
                       class="btn btn-info" id="btn-add-flag" style="width: 82px;height: 34px;">添加</a>
                    <a shiro:hasPermission="purinv:purchalist:edit" href="/purchase/change/importPage"
                       class="btn btn-info">批量标记导入</a>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var ceoApplyStatusText = ["", "未提交", "已提交", "已执行", "被驳回", "已出库"];
    var ceoApplyStatusColor = ["", " bg-gray", " bg-green", " bg-green", " bg-red", " bg-green"];
    var columns = new Array();

    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }

    /**
     * 检测浏览器
     * */
    function checkBrowser(){
        if(!checkBrowserFun()){
            alert("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href=ctx+"overview/index";
        }
    }

    /**
     * 初始化页面中搜索框中元素的显隐
     **/
    function initQueryFormControl() {
        $("#ceoRemoveUserName").hide();
        $("#removeDate").hide();
        columns = [
            {
                title: '<input title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                width: '30',
                field: 'ceoId',
                formatter: function (value, row, index) {
                    var disabled = 'disabled="disabled"';
                    if (row.ceoAppyStatus != undefined && row.ceoAppyStatus != null && row.ceoAppyStatus == 1) {
                        disabled = "";
                    }
                    var sessionUser = [[${session.user}]];
                    if (row.ceoAppPersonId != sessionUser.id) {
                        disabled = 'disabled="disabled"';
                    } else {
                        disabled = "";
                    }
                    return '<input  style="width: 30px;height: 30px" ' + disabled + ' id="cb_change' + row.ceoId + '" name="cb_change" data="' + row.ceoId + '"  type="checkbox" />';
                }
            },
            {
                title: '序号', field: 'ceoId', width: '50',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: '单据编号', field: 'ceoCode', width: '60',
                formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                }
            },

            {
                title: '标记<br>数量', field: 'ceoNeedNum', width: '60',
                formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                }
            },
            {
                title: '单价', field: 'ceoPrice', width: '60',
                formatter: function (value, row, index) {
                    if (row.ceoAppyStatus === 3 || row.ceoAppyStatus === 5) {
                        if (hasP('purinv:amount:view')) {
                            return value;
                        } else {
                            return "***";
                        }
                    } else {
                        return "--";
                    }

                }
            },
            {
                title: '需求<br>项目编号', field: 'ceoNeedProCode', formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return value;
                }
            },
            {
                title: '需求<br>项目名称',
                field: 'ceoNeedProName',
                width: '100',
                formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                }
            },
            {
                title: '需求<br>物料描述',
                field: 'ceoNeedMatName',
                width: '100',
                formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                }
            },
            // {title: '使用部门', field: 'ceoNeedDepName'},
            {
                title: '挪用<br>项目编号', field: 'ceoUseProCode'
                , formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return value;
                }
            },
            {
                title: '挪用<br>项目名称', field: 'ceoUseProName', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                    ;
                }
            },
            {
                title: '挪用<br>物料描述', field: 'ceoUseMatName', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                }
            },
            {
                title: '挪用<br>SAP编码', field: 'ceoUseItySapCode', width: '60'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                }
            },
            {
                title: '挪用<br>跟踪号', field: 'ityTrackCode', width: '60'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                }
            },
            {
                title: '仓库', field: 'whiName', width: '50', formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return '<p  style="word-wrap: break-word;width: 40px">' + value + '</p>';
                }
            },
            {
                title: '制单人', field: 'ceoAppPerson', width: '70'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '制单时间', field: 'ceoAppDate', width: '90'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return "<div style='width: 80px'>" + value + "</div>";
                }
            },
            {
                title: '提交时间', field: 'ceoSubmitDate', width: '90'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return "<div style='width: 80px'>" + value + "</div>";
                }
            },
            {
                title: '串料状态', field: 'ceoAppyStatus'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    var html = '<label class="badge ' + ceoApplyStatusColor[value] + '">' + ceoApplyStatusText[value] + '</label>';
                    return html;
                }
            },
            {
                title: '操作', field: 'ceoId', width: '100',
                formatter: function (value, row, index) {
                    var htmlText = "<div style='width: 80px'>";
                    if (hasP("purinv:purchalist:view")) {
                        htmlText += '<button class="btn btn-info btn-xs" style="margin:0px 0px 5px 0px"  onclick="seePanel(' + row.ceoId + ')">查看</button>';
                    }
                    if (row.ceoDataStatus == null && (row.ceoAppyStatus == 1 || row.ceoAppyStatus == 4)) {
                        // if (hasP("purinv:purchalist:view")) {
                        //     htmlText += '<button class="btn btn-info btn-xs" style="margin:0px 0px 5px 0px"  onclick="seePanel(' + row.ceoId + ')">查看</button>';
                        // }
                        if (hasP("purinv:purchalist:edit")) {
                            htmlText += '<button class="btn btn-success btn-xs" style="margin:0px 0px 5px 5px" onclick="submitAppy(' + row.ceoId + ')">提交</button>';
                            htmlText += '<button class="btn btn-warning btn-xs" style="margin:0" onclick="showEditPanel(' + row.ceoId + ')">修改</button>';
                            htmlText += '<button style="margin:0px 0px 0px 5px" onclick="removeApply(' + row.ceoId + ')" class="btn btn-xs btn-danger">删除</button>';
                        }
                    }
                    htmlText += "</div>";
                    return htmlText;
                }
            }
        ];
    }

    /**
     *@FunctionName: submitAppy
     *@Description: 提交
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 12:35
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function submitAppy(ceoId) {

        var data = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', ceoId);
        var sessionUser = [[${session.user}]];

        if (data.ceoAppPersonId != sessionUser.id) {
            js.modal.warning("尊敬的用户，您只可以提交自己的申请！");
            return false;
        }
        bootbox.confirm("您确认要提交此标记吗？", function (result) {
            if (result) {
                $("#toolbar").hide();
                $("#bootstrap-table").hide();
                $.post(ctx + 'purchase/change/submitAppy', {
                    ceoIds: ceoId
                }, function (result) {
                    if (result.type == "SUCCESS") {
                        js.table.refresh(table);
                        $("#toolbar").show();
                        $("#bootstrap-table").show();
                    }
                }, 'json');
            } else {
                $("#toolbar").show();
                $("#bootstrap-table").show();
            }
        });

    }

    /**
     *@FunctionName: removeApply
     *@Description: 删除作废
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 13:09
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function removeApply(ceoIds) {

        if (ceoIds == '') {
            $('input[name="cb_change"]').each(function () {
                if (!$(this).prop("disabled")) {
                    if ($(this).prop("checked")) {
                        ceoIds += $(this).attr("data") + ",";
                    }
                }
            })
            ceoIds = ceoIds.substring(0, ceoIds.length - 1);
        } else {
            var data = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', ceoIds);
            var sessionUser = [[${session.user}]];
            if (data.ceoAppPersonId != sessionUser.id) {
                js.modal.warning("尊敬的用户，您只可以删除自己的申请！");
                return false;
            }
        }
        if (ceoIds == '') {
            js.modal.alert("请选择要删除的串料申请！");
            return;
        }
        bootbox.confirm("您确认要删除此串料申请吗？", function (result) {
            if (result) {
                $("#toolbar").hide();
                $("#bootstrap-table").hide();
                $.post(ctx + 'purchase/change/removeApply', {
                    ceoIds: ceoIds
                }, function (result) {
                    if (result.type == "SUCCESS") {
                        $("#selectAll").prop('checked', false);
                        js.table.refresh(table);
                        $("#toolbar").show();
                        $("#bootstrap-table").show();
                    }
                }, 'json');
            } else {
                $("#toolbar").show();
                $("#bootstrap-table").show();
            }
        });
    }


    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: 徐一贺
     *@CreateDate: 2020/4/10 16:10
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    /**
     *@FunctionName: selectAll
     *@Description: 全选
     *@Author: 徐一贺
     *@CreateDate: 2020/4/8 15:20
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function selectAll(obj) {
        $('input[name="cb_change"]').each(function () {
            if (!$(this).prop("disabled")) {
                if ($(obj).prop("checked")) {
                    $(this).prop("checked", true);
                }
                if ($(obj).prop("checked") == false) {
                    $(this).prop("checked", false);
                }
            }
        })

    }

    /**
     *@FunctionName: loadDept
     *@Description: 加载使用单位
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 10:06
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function loadDept() {
        $.post(ctx + 'purchase/change/deptList', {}, function (result) {
            if (result.type == "SUCCESS") {
                $("#queryForm [name='ceoNeedDepId']").empty();
                $("#queryForm [name='ceoNeedDepId']").append('<option value="">全部</option>');
                for (var i = 0; i < result.data.length; i++) {
                    $("#queryForm [name='ceoNeedDepId']").append('<option value="' + result.data[i].depId + '">' + result.data[i].depName + '</option>');
                }
            }
        }, 'json');
    }

    /**
     * 初始化数据
     * */
    function initData() {
        $('#bootstrap-table').bootstrapTable('destroy');
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "purchase/change/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            striped: false,
            uniqueId: "ceoId",
            onLoadSuccess: function () {
                $('#inventoryQueryTable thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#inventoryQueryTable tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
            },
            columns: columns
        });
    }

    $(function () {
        // checkBrowser();
        loadDept();
        initQueryFormControl();
        initData();
        $("title").html($("title").html() + " —— 串料申请");

        /**
         * 当选择删除状态时
         */
        $("#queryForm [name='ceoDataStatus']").change(function () {
            if ($(this).val() === '1' || $(this).val() === '') {
                $("#ceoRemoveUserName").show();
                $("#removeDate").show();
                $("#toolbar").hide();
                columns = [
                    {
                        title: '<input title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                        width: '30',
                        field: 'ceoId',
                        formatter: function (value, row, index) {
                            var disabled = 'disabled="disabled"';
                            if (row.ceoAppyStatus != undefined && row.ceoAppyStatus != null && row.ceoAppyStatus == 1) {
                                disabled = "";
                            }
                            var sessionUser = [[${session.user}]];
                            if (row.ceoAppPersonId != sessionUser.id) {
                                disabled = 'disabled="disabled"';
                            } else {
                                disabled = "";
                            }
                            return '<input  style="width: 30px;height: 30px" ' + disabled + ' id="cb_change' + row.ceoId + '" name="cb_change" data="' + row.ceoId + '"  type="checkbox" />';
                        }
                    },
                    {
                        title: '序号', field: 'ceoId', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        title: '单据编号', field: 'ceoCode', width: '60',
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },

                    {
                        title: '标记<br>数量', field: 'ceoNeedNum', width: '60',
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },
                    {
                        title: '需求<br>项目编号', field: 'ceoNeedProCode', formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    {
                        title: '需求<br>项目名称',
                        field: 'ceoNeedProName',
                        width: '100',
                        formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                        }
                    },
                    {
                        title: '需求<br>物料描述',
                        field: 'ceoNeedMatName',
                        width: '100',
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                        }
                    },
                    // {title: '使用部门', field: 'ceoNeedDepName'},
                    {
                        title: '挪用<br>项目编号', field: 'ceoUseProCode'
                        , formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    {
                        title: '挪用<br>项目名称', field: 'ceoUseProName', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                            ;
                        }
                    },
                    {
                        title: '挪用<br>物料描述', field: 'ceoUseMatName', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                        }
                    },
                    {
                        title: '挪用<br>SAP编码', field: 'ceoUseItySapCode', width: '60'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },
                    {
                        title: '挪用<br>跟踪号', field: 'ityTrackCode', width: '60'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },
                    {
                        title: '仓库', field: 'whiName', width: '50', formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 40px">' + value + '</p>';
                        }
                    },
                    {
                        title: '制单人', field: 'ceoAppPerson', width: '70'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '制单时间', field: 'ceoAppDate', width: '90'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return "<div style='width: 80px'>" + value + "</div>";
                        }
                    },
                    {
                        title: '提交时间', field: 'ceoSubmitDate', width: '90'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return "<div style='width: 80px'>" + value + "</div>";
                        }
                    },
                    {
                        title: '串料状态', field: 'ceoAppyStatus'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            var html = '<label class="badge ' + ceoApplyStatusColor[value] + '">' + ceoApplyStatusText[value] + '</label>';
                            return html;
                        }
                    },
                    {
                        title: '删除状态', field: 'ceoDataStatus'
                        , formatter: function (value, row, index) {
                            if (value === '1') {
                                return "删除";
                            } else {
                                return "未删除";
                            }
                        }
                    },
                    {
                        title: '删除操作者', field: 'ceoRemoveUserName'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '删除时间', field: 'ceoRemoveDate'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '操作', field: 'ceoId', width: '100',
                        formatter: function (value, row, index) {
                            var htmlText = "<div style='width: 80px'>";
                            if (hasP("purinv:purchalist:view")) {
                                htmlText += '<button class="btn btn-info btn-xs" style="margin:0px 0px 5px 0px"  onclick="seePanel(' + row.ceoId + ')">查看</button>';
                            }
                            if (row.ceoDataStatus == null && (row.ceoAppyStatus == 1 || row.ceoAppyStatus == 4)) {
                                // if (hasP("purinv:purchalist:view")) {
                                //     htmlText += '<button class="btn btn-info btn-xs" style="margin:0px 0px 5px 0px"  onclick="seePanel(' + row.ceoId + ')">查看</button>';
                                // }
                                if (hasP("purinv:purchalist:edit")) {
                                    htmlText += '<button class="btn btn-success btn-xs" style="margin:0px 0px 5px 5px" onclick="submitAppy(' + row.ceoId + ')">提交</button>';
                                    htmlText += '<button class="btn btn-warning btn-xs" style="margin:0" onclick="showEditPanel(' + row.ceoId + ')">修改</button>';
                                    htmlText += '<button style="margin:0px 0px 0px 5px" onclick="removeApply(' + row.ceoId + ')" class="btn btn-xs btn-danger">删除</button>';
                                }
                            }
                            htmlText += "</div>";
                            return htmlText;
                        }
                    }
                ];
                initData();
                js.table.search(table);
            } else {
                $("#ceoRemoveUserName").hide();
                $("#removeDate").hide();
                $("#toolbar").show();
                columns = [
                    {
                        title: '<input title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                        width: '30',
                        field: 'ceoId',
                        formatter: function (value, row, index) {
                            var disabled = 'disabled="disabled"';
                            if (row.ceoAppyStatus != undefined && row.ceoAppyStatus != null && row.ceoAppyStatus == 1) {
                                disabled = "";
                            }
                            var sessionUser = [[${session.user}]];
                            if (row.ceoAppPersonId != sessionUser.id) {
                                disabled = 'disabled="disabled"';
                            } else {
                                disabled = "";
                            }
                            return '<input  style="width: 30px;height: 30px" ' + disabled + ' id="cb_change' + row.ceoId + '" name="cb_change" data="' + row.ceoId + '"  type="checkbox" />';
                        }
                    },
                    {
                        title: '序号', field: 'ceoId', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        title: '单据编号', field: 'ceoCode', width: '60',
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },

                    {
                        title: '标记<br>数量', field: 'ceoNeedNum', width: '60',
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },
                    {
                        title: '单价', field: 'ceoPrice', width: '60',
                        formatter: function (value, row, index) {
                            if (row.ceoAppyStatus === 3 || row.ceoAppyStatus === 5) {
                                if (hasP('purinv:amount:view')) {
                                    return value;
                                } else {
                                    return "***";
                                }
                            } else {
                                return "--";
                            }

                        }
                    },
                    {
                        title: '需求<br>项目编号', field: 'ceoNeedProCode', formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    {
                        title: '需求<br>项目名称',
                        field: 'ceoNeedProName',
                        width: '100',
                        formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                        }
                    },
                    {
                        title: '需求<br>物料描述',
                        field: 'ceoNeedMatName',
                        width: '100',
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                        }
                    },
                    // {title: '使用部门', field: 'ceoNeedDepName'},
                    {
                        title: '挪用<br>项目编号', field: 'ceoUseProCode'
                        , formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    {
                        title: '挪用<br>项目名称', field: 'ceoUseProName', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                            ;
                        }
                    },
                    {
                        title: '挪用<br>物料描述', field: 'ceoUseMatName', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 90px">' + value + '</p>';
                        }
                    },
                    {
                        title: '挪用<br>SAP编码', field: 'ceoUseItySapCode', width: '60'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },
                    {
                        title: '挪用<br>跟踪号', field: 'ityTrackCode', width: '60'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 50px">' + value + '</p>';
                        }
                    },
                    {
                        title: '仓库', field: 'whiName', width: '50', formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return '<p  style="word-wrap: break-word;width: 40px">' + value + '</p>';
                        }
                    },
                    {
                        title: '制单人', field: 'ceoAppPerson', width: '70'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '制单时间', field: 'ceoAppDate', width: '90'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return "<div style='width: 80px'>" + value + "</div>";
                        }
                    },
                    {
                        title: '提交时间', field: 'ceoSubmitDate', width: '90'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return "<div style='width: 80px'>" + value + "</div>";
                        }
                    },
                    {
                        title: '串料状态', field: 'ceoAppyStatus'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            var html = '<label class="badge ' + ceoApplyStatusColor[value] + '">' + ceoApplyStatusText[value] + '</label>';
                            return html;
                        }
                    },
                    {
                        title: '操作', field: 'ceoId', width: '100',
                        formatter: function (value, row, index) {
                            var htmlText = "<div style='width: 80px'>";
                            if (hasP("purinv:purchalist:view")) {
                                htmlText += '<button class="btn btn-info btn-xs" style="margin:0px 0px 5px 0px"  onclick="seePanel(' + row.ceoId + ')">查看</button>';
                            }
                            if (row.ceoDataStatus == null && (row.ceoAppyStatus == 1 || row.ceoAppyStatus == 4)) {
                                // if (hasP("purinv:purchalist:view")) {
                                //     htmlText += '<button class="btn btn-info btn-xs" style="margin:0px 0px 5px 0px"  onclick="seePanel(' + row.ceoId + ')">查看</button>';
                                // }
                                if (hasP("purinv:purchalist:edit")) {
                                    htmlText += '<button class="btn btn-success btn-xs" style="margin:0px 0px 5px 5px" onclick="submitAppy(' + row.ceoId + ')">提交</button>';
                                    htmlText += '<button class="btn btn-warning btn-xs" style="margin:0" onclick="showEditPanel(' + row.ceoId + ')">修改</button>';
                                    htmlText += '<button style="margin:0px 0px 0px 5px" onclick="removeApply(' + row.ceoId + ')" class="btn btn-xs btn-danger">删除</button>';
                                }
                            }
                            htmlText += "</div>";
                            return htmlText;
                        }
                    }
                ];
                initData();
                js.table.search(table);
            }
        });


        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });
        /**
         * 批量提交
         */
        $("#btn_submitSelectItems").on('click', function () {

            var ceoIds = "";
            $('input[name="cb_change"]').each(function () {
                if (!$(this).prop("disabled")) {
                    if ($(this).prop("checked")) {
                        ceoIds += $(this).attr("data") + ",";
                    }

                }
            })
            ceoIds = ceoIds.substring(0, ceoIds.length - 1);
            if (ceoIds == "") {
                js.modal.alert("请选择要提交的串料申请！");
                return;
            }
            js.modal.confirm("尊敬的用户，您确定要提交这些申请吗？", function () {
                $.post(ctx + 'purchase/change/submitAppy', {
                    ceoIds: ceoIds
                }, function (result) {
                    if (result.type == "SUCCESS") {
                        js.table.refresh(table);
                    }
                }, 'json');
            });
        });

        $("#queryForm [name='whiId']").change(function () {
            $("#queryForm input[name='whiIds']").val($("#queryForm [name='whiId']").val());
        });

        $("#queryForm [name='ceoAppyStatusTextSelect']").change(function () {
            $("#queryForm input[name='ceoAppyStatusText']").val($("#queryForm [name='ceoAppyStatusTextSelect']").val());
            // $("#queryForm [name='ceoAppyStatusTextSelect'] option:selected").each(function () {
            //     var optionValArray = $("#queryForm [name='ceoAppyStatusTextSelect']").val();
            //     if ($(this).val() == "-1") {
            //         var optionValArray = new Array();
            //         optionValArray.push('-1');
            //         $("#queryForm [name='ceoAppyStatusTextSelect']").selectpicker('val', optionValArray);
            //         $("#queryForm input[name='ceoAppyStatusText']").val("");
            //
            //         js.modal.warning("请取消选择全部！");
            //
            //     } else if ($(this).val() == "-1" && $("#queryForm [name='ceoAppyStatusTextSelect']").val().length > 1) {
            //         if ($("#queryForm [name='ceoAppyStatusTextSelect']").val().indexOf("-1") != -1) {
            //             delete optionValArray[0];
            //         }
            //         $("#queryForm [name='ceoAppyStatusTextSelect']").selectpicker('val', optionValArray);
            //         $("#queryForm input[name='ceoAppyStatusText']").val($("#queryForm [name='ceoAppyStatusTextSelect']").val());
            //     } else if ($(this).val() != "-1" && $("#queryForm [name='ceoAppyStatusTextSelect']").val()[0] != "-1") {
            //
            //         var optionValArray = $("#queryForm [name='ceoAppyStatusTextSelect']").val();
            //         if ($("#queryForm [name='ceoAppyStatusTextSelect']").val().indexOf("-1") != -1) {
            //             delete optionValArray[0];
            //         }
            //         $("#queryForm [name='ceoAppyStatusTextSelect']").selectpicker('val', optionValArray);
            //         $("#queryForm input[name='ceoAppyStatusText']").val($("#queryForm [name='ceoAppyStatusTextSelect']").val());
            //     }
            // });
        });
    });

    /**
     *@FunctionName: seePanel
     *@Description: 查看
     *@Author: 徐一贺
     *@CreateDate: 2020/4/24 12:48
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function seePanel(ceoId) {
        location.href = "/purchase/change/createPage/see/" + ceoId;
    }

    /**
     *@FunctionName: showEditPanel
     *@Description: 修改
     *@Author: 徐一贺
     *@CreateDate: 2020/4/24 12:48
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function showEditPanel(ceoId) {
        var data = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', ceoId);
        var sessionUser = [[${session.user}]];
        if (data.ceoAppPersonId != sessionUser.id) {
            js.modal.warning("尊敬的用户，您只可以修改自己的申请！");
            return false;
        }
        location.href = "/purchase/change/createPage/edit/" + ceoId;
    }
</script>
</body>
</html>
